home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / rint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.1 KB  |  104 lines

  1. #if !defined (__M68881__) && !defined (sfp004)
  2.  
  3. /*
  4.  * PDC I/O Library Copyright (C) 1987 by J.A. Lydiatt.
  5.  * Modifications for PDC release 3.3 Copyright (C) 1988 Lionel D. Hummel.
  6.  * PDC Software Distribution Copyright (C) 1988 Lionel Hummel and Paul Petersen.
  7.  *
  8.  * This code is freely redistributable upon the conditions that this notice
  9.  * remains intact and that modified versions of this file not be included
  10.  * as part of the PDC Software Distribution without the express consent of
  11.  * the copyright holders.
  12.  */
  13.  
  14. #include <math.h>
  15.  
  16. /*    round.c - performs rounding
  17.  */
  18.  
  19. /* Returns an integer rounded from a double.  In case of fraction exactly
  20.  * midway, round chooses nearest even value.
  21.  */
  22.  
  23. double rint(num)
  24. double num;
  25. {
  26.     double ipart;
  27.     int    ival;
  28.     double frac;
  29.  
  30.     frac = modf(num, &ipart);
  31.  
  32.     ival = ipart;
  33.     if ( (frac > 0.5) || ((frac == 0.5) && (ival%2)) )
  34.         ival++;
  35.  
  36.     return((double) ival);
  37. }
  38. #endif    /* __M68881__, sfp004    */
  39.  
  40.  
  41. #ifdef __M68881__
  42.  
  43. double rint(double x)
  44. {
  45.   double value;
  46. #if 0
  47.   int rounding_mode, round_nearest;
  48.  
  49.   __asm volatile ("fmove%.l fpcr,%0"
  50.           : "=dm" (rounding_mode)
  51.           : /* no inputs */ );
  52.   round_nearest = rounding_mode & ~0x30;
  53.   __asm volatile ("fmove%.l %0,fpcr"
  54.           : /* no outputs */
  55.           : "dmi" (round_nearest));
  56. #endif 0
  57.   __asm volatile ("fint%.x %1,%0"
  58.           : "=f" (value)
  59.           : "f" (x));
  60. #if 0
  61.   __asm volatile ("fmove%.l %0,fpcr"
  62.           : /* no outputs */
  63.           : "dmi" (rounding_mode));
  64. #endif 0
  65.   return value;
  66. }
  67. #endif __M68881__
  68. #ifdef    sfp004
  69. __asm("
  70.  
  71. | pml compatible lib for the atari sfp004
  72. |
  73. | Michael Ritzert, Oktober 1990
  74. | ritzert@dfg.dbp.de
  75. |
  76. | FUNCTION:    DOUBLE RINT( DOUBLE X )
  77. |
  78. | base =    0xfffa50
  79. | the fpu addresses are taken relativ to 'base':
  80.  
  81. comm =     -6
  82. resp =    -16
  83. zahl =      0
  84.  
  85. .text
  86.     .globl _rint
  87. .even
  88. _rint:
  89.     lea    0xfffa50,a0
  90. |    movew    #0x5403,a0@(comm)    | fintrz to fp0
  91.     movew    #0x5401,a0@(comm)    | fint   to fp0
  92.     cmpiw    #0x8900,a0@(resp)    | check
  93.     movel    a7@(4),a0@        | load arg_hi
  94.     movel    a7@(8),a0@        | load arg_low
  95.     movew    #0x7400,a0@(comm)    | result to d0
  96. | wait
  97.     .long    0x0c688900, 0xfff067f8
  98.     movel    a0@,d0
  99.     movel    a0@,d1
  100.      rts
  101.  
  102. ");
  103. #endif    sfp004
  104.